package com.ft.oa.web.customer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ft.oa.domain.customer.Customer;
import com.ft.oa.domain.customer.CustomerOrganiza;
import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.service.customer.CustomerOrganizaService;
import com.ft.oa.service.customer.CustomerService;
import com.ft.oa.web.customer.rq.CustomerPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private CustomerOrganizaService customerOrganizaService;

    /**
     * 根据条件查询企业
     */
    @PostMapping("/list")
    public ApiResult selectCustomerById(@RequestBody CustomerPage customerPage){
        IPage<Customer> customerPages = customerService.selectCustomerById(customerPage);
        return ApiResult.successWithData(customerPages);
    }

    /**
     * 添加企业信息
     * @param customer
     * @return
     */
    @PostMapping("/insert")
    public ApiResult insertCustomer(@RequestBody Customer customer){
        customerService.insertCustomer(customer);
        return ApiResult.simpleSuccess();
    }

    /**
     * 修改企业信息
     * @param customer
     * @return
     */
    @PostMapping("/update")
    public ApiResult updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return ApiResult.simpleSuccess();
    }

    /**
     * 删除企业
     * @param customerPage
     * @return
     */
    @PostMapping("/delete")
    public ApiResult deleteCustomer(@RequestBody CustomerPage customerPage){
        customerService.deleteCustomer(customerPage.getId());
        return ApiResult.simpleSuccess();
    }

    /**
     * 查询所有公司
     */
    @PostMapping("/select")
    public ApiResult selectCustomer(){
        List<Customer> customers = customerService.selectCustomer();
        return ApiResult.successWithData(customers);
    }

    /**
     * 查询公司组织架构
     */
    @PostMapping("sel")
    public ApiResult sel(@RequestBody CustomerOrganiza customerOrganiza){

        List<CustomerOrganiza> customerOrganizaList = customerOrganizaService.list(customerOrganiza);
        return ApiResult.successWithData(customerOrganizaList);
    }

    @PostMapping("/inter")
    public ApiResult inter (@RequestBody CustomerOrganiza customerOrganiza){
       customerOrganizaService.insert(customerOrganiza);
       return ApiResult.simpleSuccess();
    }
}